﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace eStore.Models
{
    public class CategoryRepository:ICategoryRepository
    {
        private eStoreContainer _container;

        public CategoryRepository() {
            _container = new eStoreContainer();
        }

        public IEnumerable<Category> GetLatest(int? iTopLatest)
        {
            return null;
        }

        public void Add(Category objT)
        {
            throw new NotImplementedException();
        }

        public void Remove(Category objT)
        {
            throw new NotImplementedException();
        }

        public void Update(Category objT)
        {
            throw new NotImplementedException();
        }

        public Category GetById(int iID)
        {
            throw new NotImplementedException();
        }

        public Category GetById(string sID)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<Category> GetAll()
        {
            var allCategories = (from category in _container.Categories.Include("Products")
                                 select category);

            return allCategories;
        }

        public Category GetByCategoryName(string sCategoryName)
        {
            var allMatchedCategory = (from category in _container.Categories.Include("Products")
                                      where category.CategoryName.Contains(sCategoryName)
                                      select category).FirstOrDefault();

            return allMatchedCategory;
        }
    }
}